package com.ddy.test.quartz;

import com.ddy.test.thread.SynchronizedFunction;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
 * Created by ddy on 2017/12/6.
 */
public class TriggerDemo {
    /**
     *
     * @param args
     * @throws Exception
     */

    public static void main(String[] args) throws Exception {
        multiFunctionTest();

        }
    public static void simpleTest() {
        System.out.println(new Date() + " begin..." );
        JobDetail jobDetail = new JobDetail("j_job1", "j_group1", JobDemo.class);
        long time = System.currentTimeMillis() + 1000 * 6;
        SimpleTrigger simpleTrigger = new SimpleTrigger("t_job1", "t_group_1", new Date(time));

        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = null;
        try {
            scheduler = schedulerFactory.getScheduler();
            scheduler.scheduleJob(jobDetail, simpleTrigger);
            scheduler.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }


    public static void multiFunctionTest() throws SchedulerException {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();
        Date time = new Date();
        long timeMillis = time.getTime() + 1000 * 300;
        for(int i=0;i<100;i++){
            System.out.println(new Date(timeMillis) + "j_job " + i + " begin..." );
            JobDetail jobDetail = new JobDetail("j_job_"+i, "j_group", JobDemo.class);
            SimpleTrigger simpleTrigger = new SimpleTrigger("t_job_"+i, "t_group", new Date(timeMillis));
            scheduler.scheduleJob(jobDetail, simpleTrigger);
        }

        Trigger trigger3 = scheduler.getTrigger("t_job_3", "t_group");
        String[] jobNames3 = scheduler.getJobNames("j_group");
        scheduler.start();
    }
}
